package com.bkitmobile.kesu.android.GUI;

import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
import com.bkitmobile.kesu.android.ClassInfo.*;
import com.bkitmobile.kesu.android.connectServer.staticClass;
public class ManageOverlay extends Overlay {
	private Paint redPaint;
	private Paint grayPaint;
	private Paint bluePaint;
	private List<LocationUserInfo> lsUser;
	public ManageOverlay(List<LocationUserInfo> lsUser)
	{
		redPaint = new Paint();
	    redPaint.setARGB(255, 255, 0, 0);
	    redPaint.setAntiAlias(true);
	    redPaint.setFakeBoldText(true);
	    grayPaint = new Paint();
	    grayPaint.setARGB(200, 200, 200, 200);
	    grayPaint.setAntiAlias(true);
	    bluePaint = new Paint();
	    bluePaint.setARGB(255, 10, 10, 255);
	    bluePaint.setAntiAlias(true);
	    bluePaint.setFakeBoldText(true);
	    this.lsUser = lsUser;
	}
	private static int markerRadius = 7;
	private void drawOneLocation(Canvas canvas, MapView mapView
			,Point thisPoint,Paint paint,String text)
	{
		
		RectF oval = new RectF(thisPoint.x-markerRadius,
		thisPoint.y-markerRadius,
			thisPoint.x+markerRadius,
			thisPoint.y+markerRadius);    
		canvas.drawOval(oval, grayPaint);
		oval.inset(2, 2);
		canvas.drawOval(oval, paint);  
		
        float textWidth = paint.measureText(text);
        float textHeight = paint.getTextSize();

        RectF textRect = new RectF(thisPoint.x+markerRadius+10, thisPoint.y-textHeight,
        		thisPoint.x+markerRadius+14+textWidth, thisPoint.y+4);

        canvas.drawRoundRect(textRect, 3, 3, grayPaint);
        canvas.drawText(text, thisPoint.x+markerRadius+12, thisPoint.y, paint);
        
	}
	@Override
	public void draw(Canvas canvas, MapView mapView,
										boolean shadow) {
		drawListUserLocation(canvas, mapView, shadow);
	    //else drawAllFriends(canvas, mapView, shadow);
		super.draw(canvas, mapView, shadow);
		
	}
	private void drawListUserLocation(Canvas canvas, MapView mapView,
			boolean shadow) {
		// TODO Auto-generated method stub
		Projection projection = mapView.getProjection();   
	    Point lPoint = null;
		for (LocationUserInfo tmp:lsUser)
		{
			GeoPoint geopoint = staticClass.getPoint(tmp.getLatitude()
	        		  , tmp.getLongitude());
			Point point = new Point();
            projection.toPixels(geopoint, point);
			drawOneLocation(canvas, mapView, point, bluePaint, tmp.getTime());
			if (lPoint!=null) canvas.drawLine(lPoint.x, lPoint.y, point.x, point.y, bluePaint);
			lPoint = point;
		}
	}
	
}
